package dyyx;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

public class JedisClusterTest {
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("hello,JedisClusterTest");
		// 连接非 cluster 集群  测试
		
		String ip = "127.0.0.1";
		ip = "10.57.30.34";
		
		Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
		// Jedis Cluster will attempt to discover cluster nodes automatically
		jedisClusterNodes.add(new HostAndPort(ip, 6379));
		// JedisCluster jc = new JedisCluster(jedisClusterNodes);
		
		// public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout,
		//	      int maxAttempts, String password, final GenericObjectPoolConfig poolConfig)
		
		int connectionTimeout = 2000;
		int soTimeout = 2000;
		int maxAttempts =5;
		String password = "123456";
		
		// password = null;
		
		GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
		
		JedisCluster jc = new JedisCluster(jedisClusterNodes,connectionTimeout,soTimeout,maxAttempts,password,poolConfig);
		
		
		
		jc.set("foo", "bar");
		String value = jc.get("foo");
		
		//  redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster support disabled
		//  redis.conf  cluster-enabled yes
		// ./redis-server  ../redis.conf
		//  redis.clients.jedis.exceptions.JedisClusterException: CLUSTERDOWN Hash slot not served

		jc.close();
		

	}
}
